import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

/// storage_service.dart
///
/// Created by fuchuanwei on Tue Feb 21 2023.
///
/// Description: 数据存储服务
///
class SharedPreferencesService extends GetxService {
  late SharedPreferences _pref;
  @override
  void onInit() async {
    super.onInit();
    _pref = await SharedPreferences.getInstance();
  }

  ///设置字符串值
  Future<void> setStrValue(String key, String value) async {
    await _pref.setString(key, value);
  }

  ///获取字符串值
  String? getStrValue(String key) {
    return _pref.getString(key);
  }

  ///设置int值
  Future<void> setIntValue(String key, int value) async {
    await _pref.setInt(key, value);
  }

  ///获取int值
  int? getIntValue(String key) {
    return _pref.getInt(key);
  }

  ///设置double值
  Future<void> setDoubleValue(String key, double value) async {
    await _pref.setDouble(key, value);
  }

  ///获取double值
  double? getDoubleValue(String key) {
    return _pref.getDouble(key);
  }

  ///设置bool值
  Future<void> setBoolValue(String key, bool value) async {
    await _pref.setBool(key, value);
  }

  ///获取bool值
  bool? getBoolValue(String key) {
    return _pref.getBool(key);
  }

  Future<void> removeValue(String key) async {
    await _pref.remove(key);
  }
}
